package com.wujie.market.controller;

import com.wujie.market.po.Goods;
import com.wujie.market.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: GoodsController
 * Description:
 * date: 2023/1/27 19:11
 *
 * @author 吴杰
 * @since JDK 1.8.0_31
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/list")
    public List<Goods> list(){
        return goodsService.querylist();
    }

    @RequestMapping("/plus")
    public  List<Goods> plus(String gType,String gName){
        return goodsService.listPlus(gType,gName);
    }
    /**
    * Description: 通过ID查询
    * @author: 吴杰
    * @date: 2023/2/1 0:02
    * @param:
     * * @return:
    */
    @RequestMapping("/queryId")
    public Goods queryById(int gId){
        return goodsService.queryById(gId);
    }

    /**
    * Description:修改货物信息和增加库存
    * @author: 吴杰
    * @date: 2023/2/3 23:17
    * @param:
     * * @return:
    */
    @RequestMapping("/save")
    public void save(@RequestBody Goods goods) {
        goodsService.savaGoods(goods);
    }

    /**
    * Description:插入数据
    * @author: 吴杰
    * @date: 2023/2/15 19:46
    * @param:
     * * @return:
    */
    @RequestMapping("/insert")
    public Map<String,Object> insertGoods(@RequestBody Goods goods){
        Map<String,Object> map = new HashMap<>();
        int result = goodsService.insertGoods(goods);
        if (result > 0) {
            map.put("code",200);
            map.put("message","成功插入");
        }else {
            map.put("code",400 );
            map.put("message","插入失败");
        }
        return map;
    }
    /**
    * Description:查询需要补货的数据
    * @author: 吴杰
    * @date: 2023/2/15 19:46
    * @param:
     * * @return:
    */
    @RequestMapping("/warn")
    public List<Goods> queryWarnGoods(){

        return goodsService.queryWarnGoods();
    }

    /**
    * Description:查询销量最多
    * @author: 吴杰
    * @date: 2023/2/22 20:32
    * @param:
     * * @return:
    */
    @RequestMapping("/max")
    public List<Goods> queryMax(){
        return goodsService.queryMaxSale();
    }
}
